package com.sunma.assets.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sunma.common.annotation.Log;
import com.sunma.common.core.controller.BaseController;
import com.sunma.common.core.domain.AjaxResult;
import com.sunma.common.enums.BusinessType;
import com.sunma.assets.domain.Assets;
import com.sunma.assets.service.IAssetsService;
import com.sunma.common.utils.poi.ExcelUtil;
import com.sunma.common.core.page.TableDataInfo;

/**
 * 资产详细信息Controller
 * 
 * @author sunma
 * @date 2024-07-05
 */
@RestController
@RequestMapping("/assets/assets")
public class AssetsController extends BaseController
{
    @Autowired
    private IAssetsService assetsService;

    /**
     * 查询资产详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:list')")
    @GetMapping("/list")
    public TableDataInfo list(Assets assets)
    {
        startPage();
        List<Assets> list = assetsService.selectAssetsList(assets);
        return getDataTable(list);
    }

    /**
     * 导出资产详细信息列表
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:export')")
    @Log(title = "资产详细信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Assets assets)
    {
        List<Assets> list = assetsService.selectAssetsList(assets);
        ExcelUtil<Assets> util = new ExcelUtil<Assets>(Assets.class);
        util.exportExcel(response, list, "资产详细信息数据");
    }

    /**
     * 获取资产详细信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(assetsService.selectAssetsById(id));
    }

    /**
     * 新增资产详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:add')")
    @Log(title = "资产详细信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Assets assets)
    {
        return toAjax(assetsService.insertAssets(assets));
    }

    /**
     * 修改资产详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:edit')")
    @Log(title = "资产详细信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Assets assets)
    {
        return toAjax(assetsService.updateAssets(assets));
    }

    /**
     * 删除资产详细信息
     */
    @PreAuthorize("@ss.hasPermi('assets:assets:remove')")
    @Log(title = "资产详细信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(assetsService.deleteAssetsByIds(ids));
    }
}
